#!/bin/bash

REPO_ROOT_DIR="/tmp"
REPO_DIR=$REPO_ROOT_DIR/gitRepo

PORT_OCCUPIED=`netstat -na | grep 9418`

if [ ! -d $REPO_DIR ] && [ -z $PORT_OCCUPIED ] 
then 
    echo "Folder $REPO_DIR will be created under which a git repository will be setup via git daemon"
    mkdir $REPO_DIR && cd $REPO_DIR
    echo "Start setting up git repository ... "
    git init
    touch init.txt
    echo "blabla" >> init.txt
    git add init.txt
    git commit -m "add file init.txt to this repo to make sure this is not an empty repo"
    git daemon --verbose --export-all --enable=receive-pack & 
    echo "git repository git://$HOSTNAME$REPO_DIR setup finished."
else
    echo "Folder $REPO_DIR already exists or port 9418 is occupied. Please check it first."
fi
